<?php
/**
 * Copyright 2011  SURFfoundation
 * 
 * This file is part of ESCAPE.
 * 
 * ESCAPE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ESCAPE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ESCAPE.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information:
 * http://escapesurf.wordpress.com/
 * http://www.surffoundation.nl/
 * 
 * Contact: d.vierkant@utwente.nl
 * 
 * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3
 */
?>
<?php
	/* @var $repository escape_repository_Repository */
	$repository =& $this->requestAttributes['repository'];
	/* @var $repositoryUi escape_repositoryui_RepositoryUi */
	$repositoryUi =& $this->requestAttributes['repositoryUi'];
	/* @var $oreObject escape_repository_OreObject */
	$oreObject =& $this->requestAttributes['oreObject'];
	/* @var $aggregation escape_repository_OreAggregation */
	$aggregation =& $this->requestAttributes['aggregation'];

	$repositoryUi->setTemplateFromAggregation($aggregation);
	
	$templateVariables = array();
	$templateVariables['title'] = $oreObject->getTitle();

	// add link to aggregation and resource map to HTML HEAD
	$templateVariables['head_html']  = '<link rel="resourcemap" type="application/rdf+xml" href="' . htmlspecialchars($aggregation->getRemExternalUri()) . '" />' . "\n";
	$templateVariables['head_html'] .= '<link rel="aggregation" href="' . htmlspecialchars($aggregation->getExternalUri()) . '" />' . "\n";
	$templateVariables['head_html'] .= '<link rel="alternate" type="application/rdf+xml" href="' . $repository->config['server_url'] . '/rdf/' . $oreObject->getId() . '" title="RDF/XML version"/>' . "\n"; 	
	
	$templateVariables['head_html'] .= '<link type="text/css" href="/rsc/css/visualizer.css?v1" rel="Stylesheet" />
<link type="text/css" href="/rsc/css/visualizer-skin.css?v1" rel="Stylesheet" />
<!--[if IE 6]>    
<link type="text/css" href="/rsc/css/visualizer-ie6.css?v1" rel="Stylesheet" />
<![endif]-->
';
	$templateVariables['head_html'] .= '<script type="text/javascript" src="/rsc/js/visualizer_compiled_min.js?v1"></script>';
//	$templateVariables['head_html'] .= '<script type="text/javascript" src="/rsc/js/visualizer_compiled.js?v1"></script>';
	
	$this->requestAttributes['templateVariables'] =& $templateVariables;
?>
<?php $this->displayHeader(); ?>

<div id="visualizerCanvas"></div>

<div id="objectDetails"></div>


<script type="text/javascript">
<!--
var selectedObjectId = escape_escapeUi.getUrlHashParameter("id");
if(selectedObjectId == undefined)
{
	selectedObjectId = <?php print json_encode($oreObject->getId()); ?>;
	escape_escapeUi.setUrlHashParameter("id", selectedObjectId, true);
}

var app = new VisualizerApp("visualizerCanvas", selectedObjectId,
        {
//          dataUrl: <?php print json_encode($aggregation->getRemExternalUri() . '?format=application%2Fjson&title_predicate=http%3A%2F%2Fpurl.org%2Fdc%2Felements%2F1.1%2Ftitle'); ?>,
//          dataFormat: "application/json",
          dataUrl: <?php print json_encode($aggregation->getRemExternalUri() . '?title_predicate=http%3A%2F%2Fpurl.org%2Fdc%2Felements%2F1.1%2Ftitle'); ?>,
          schemaUrl: <?php print json_encode($repository->config['server_url'] . '/schema?format=application%2Fjson'); ?>,
          schemaFormat: "application/json",
          idProperty: "http://purl.utwente.nl/ns/escape-system.owl#id",
          titleProperties: ["http://purl.org/dc/elements/1.1/title"],
          annotationTypeId: "http://purl.utwente.nl/ns/escape-annotations.owl#RelationAnnotation",
          objectAnnotationTypeId: "http://purl.utwente.nl/ns/escape-annotations.owl#object",
          subjectAnnotationTypeId: "http://purl.utwente.nl/ns/escape-annotations.owl#subject",
          descriptionAnnotationTypeId: "http://purl.org/dc/terms/description",
          imageTypeId: "http://xmlns.com/foaf/0.1/img",
          useHistoryManager: false,
          showProperties: false,
          objectLinkTarget: "_none",
          baseClassTypes: {
            "http://purl.utwente.nl/ns/escape-pubtypes.owl#Publication": "publication",
            "http://purl.org/dc/dcmitype/MovingImage": "video",
            "http://purl.utwente.nl/ns/escape-events.owl#Event": "event",
            "http://purl.utwente.nl/ns/escape-projects.owl#Topic": "topic"
          }
        });


var graphController = new escape_escapeUi.GraphController('graphController', $('objectDetails'), <?php print json_encode($aggregation->getId()); ?>, <?php print json_encode($aggregation->getExternalUri()); ?>, 'id');
graphController.startUrlPoller(100);

graphController.setGraphViewerSelectHandler(app.loadObject.bind(app));

app.subscribe("*.load-object-ready", function(event) { graphController.selectObjectByIdWithoutViewerUpdate(event.data); }, graphController);
app.subscribe("*.object-uri-click", function(event) { escape_escapeUi.Scroller.scrollTo($('objectDetails')); }, graphController);

//-->
</script>

<?php $this->displayFooter(); ?>
